package com.lyh.web.controller.system;

import com.lyh.common.core.domain.AjaxResult;
import com.lyh.system.domain.SysRelationValue;
import com.lyh.system.domain.vo.GoodsVo;
import com.lyh.system.domain.vo.IndexVo;
import com.lyh.system.mapper.GoodsMapper;
import com.lyh.system.service.IGoodsService;
import com.lyh.system.service.ISysRelationValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lyh.common.config.RuoYiConfig;
import com.lyh.common.utils.StringUtils;

import java.util.List;

/**
 * 首页
 *
 * @author lyh
 */
@RestController
public class SysIndexController
{
    /** 系统基础配置 */
    @Autowired
    private RuoYiConfig ruoyiConfig;

    @Autowired
    private IGoodsService goodsService;

    @Autowired
    private GoodsMapper goodsMapper;

    @Autowired
    private ISysRelationValueService sysRelationValueService;

    /**
     * 访问首页，提示语
     */
    @RequestMapping("/")
    public String index()
    {
        return StringUtils.format("欢迎使用{}后台管理框架，当前版本：v{}，请通过前端地址访问。", ruoyiConfig.getName(), ruoyiConfig.getVersion());
    }

    @GetMapping("/app")
    public AjaxResult list() {
        IndexVo indexVo = new IndexVo();
        List<GoodsVo> goodsVos = goodsService.selectGoods();
        for (GoodsVo goodsVo : goodsVos) {
            Long monthlySales = goodsMapper.goodsMonthlySales(goodsVo.getId());
            goodsVo.setMonthlySales(monthlySales);
        }
        List<SysRelationValue> appBannerInfo = sysRelationValueService.getAppBannerInfo();
        indexVo.setGoodsVos(goodsVos);
        indexVo.setBannerImageList(appBannerInfo);
        return AjaxResult.success(indexVo);
    }
}
